package com.twq.func.innerctrl

import scala.annotation.tailrec

/**
 * Created by tangweiqun on 2017/11/28.
 */
object WithoutContinueBreak {
  def main(args: Array[String]): Unit = {
    //1、不用continue和break的循环
    var i = 0
    var foundIt = false
    while (i < args.length && !foundIt) {
      if (!args(i).startsWith("-")) {
        if (args(i).endsWith(".scala"))
          foundIt = true
      }
      i = i + 1
    }

    //2、消除var
    def searchFrom(i: Int): Int =
      if (i >= args.length) -1
      else if (args(i).startsWith("-")) searchFrom(i + 1)
      else if (args(i).endsWith(".scala")) i
      else searchFrom(i + 1)

    val j = searchFrom(0)


    //3、非得使用break的话，我们可以使用scala.util.control中的break
    import scala.util.control.Breaks._
    import java.io._
    val in = new BufferedReader(new InputStreamReader(System.in))
    breakable {
      while (true) {
        println("? ")
        if (in.readLine() == "") break
      }
    }
  }
}
